<template>
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :before-close="cancel" :close-on-click-modal="false" v-dialogDrag>
      <el-form ref="form" :model="form" :rules="rules"  label-width="120px">
            <el-tabs  class="detail-tab" type="card">
                <el-tab-pane label="质检单" >
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item label="质检报告" prop="inspectReport">
                        <image-upload v-model="form.inspectReport"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item label="备注" prop="remark">
                        <el-input type="textarea" v-model="form.remark" placeholder="请输入备注"/>
                      </el-form-item>
                    </el-col>
                  </el-row>


                </el-tab-pane>
            </el-tabs>
        </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm()" >提 交</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {updateAction, getById, addAction} from '@/api/manage'

  export default {
    name: "ZhijiandanForm",
    components: {

    },
    data() {
      return {
        title: "上传质检单",
        open: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        rows: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 销售信息管理表格数据
        form: {
        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 20,
          inspectState: "1",
          dateRange: "1",
          params: {},
        },
        rules:{
          inspectName: [
            { required: true, message: "质检人不能为空", trigger: "blur" }
          ],
          inspectDate: [
            { required: true, message: "请输入质检时间", trigger: "blur" }
          ],
        },
        url: {
          getById:'/lvDaohuoDetail/lvDaohuoDetail/',
            edit:'/lvDaohuoDetail/lvDaohuoDetail/edit',
        },
        tableMaxHeight: window.innerHeight - 320,
      };
    },
    created() {
      // this.intDictsForPrj();
      window.addEventListener('resize', this.getTableHeight);
    },
    destroyed() {
      window.removeEventListener('resize', this.getTableHeight);
    },
    methods: {
      getTableHeight() {
        this.tableHeight = window.innerHeight - 320
      },
      inspectShow(row){
        /*this.queryParams.id=row.id;
        this.form.id=row.id;
        this.form.zhijiandan=row.zhijiandan;
        this.form.remark=row.remark;
        this.open=true;*/
        this.reset();
        getById(this.url.getById, row.id ).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "上传质检单";
        });
      },
      // 取消按钮
      cancel() {
        this.reset();
        this.open = false;
      },
      reset() {
        this.form = {
          id: null,
          daohuoCount: null,
        };
        this.resetForm("form");
      },
      //
      submitForm() {
        if (this.form.id != null) {
          this.$refs["form"].validate(valid => {
            if (valid) {
              updateAction(this.url.edit, this.form).then(response => {
                this.$modal.msgSuccess("提交成功");
                this.open = false;
                this.$emit('ok');
              });
            }
          });

        }
      },
    }
  };
</script>
